package com.example.asus.testskip;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.asus.testskip.DGPhone.ShowActivity;
import com.example.asus.testskip.DGPhone.phone.MyPhoneCallListener;
import com.example.asus.testskip.DGPhone.phone.OverLayActivity;
import com.example.asus.testskip.DGPhone.phone.OverlayView;

/* renamed from: dg.ca.com.DGPhone.MainActivity */
public class MainActivity extends Activity {
    /* access modifiers changed from: private */
    public EditText phone_edit;
    private Button setting;
    private Button skip_button;
    /* access modifiers changed from: private */
    public EditText welcome_edit;
    /* access modifiers changed from: private */
    public EditText welcome_en_edit;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(1);
        getWindow().setFlags(1024, 1024);
        getWindow().addFlags(128);
        LayoutParams params = getWindow().getAttributes();
        params.systemUiVisibility = 1;
        getWindow().setAttributes(params);
        setContentView(R.layout.call_main);
        this.phone_edit = (EditText) findViewById(R.id.phone_edit);
        this.welcome_edit = (EditText) findViewById(R.id.welcome_edit);
        this.welcome_en_edit = (EditText) findViewById(R.id.welcome_en_edit);
        this.skip_button = (Button) findViewById(R.id.skip_button);
        this.skip_button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ShowActivity.class);
                intent.putExtra("welcome", MainActivity.this.welcome_edit.getText().toString().trim());
                intent.putExtra("welcomeen", MainActivity.this.welcome_en_edit.getText().toString().trim());
                intent.putExtra("phone", MainActivity.this.phone_edit.getText().toString().trim());
                MainActivity.this.startActivity(intent);
            }
        });
        this.setting = (Button) findViewById(R.id.setting);
        this.setting.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Editor editor = MainActivity.this.getSharedPreferences("DG_PHONESHOW", 0).edit();
                editor.putString("welcome", MainActivity.this.welcome_edit.getText().toString().trim());
                editor.putString("welcomeen", MainActivity.this.welcome_en_edit.getText().toString().trim());
                editor.putString("phone", MainActivity.this.phone_edit.getText().toString().trim());
                editor.commit();
                Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(MainActivity.this, ShowActivity.class);
                intent.putExtra("welcome", MainActivity.this.welcome_edit.getText().toString().trim());
                intent.putExtra("welcomeen", MainActivity.this.welcome_en_edit.getText().toString().trim());
                intent.putExtra("phone", MainActivity.this.phone_edit.getText().toString().trim());
                MainActivity.this.startActivity(intent);
            }
        });
        initDate();
        telephony();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private void telephony() {
        //获得相应的系统服务
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        if(tm != null) {
            try {
                MyPhoneCallListener myPhoneCallListener = new MyPhoneCallListener();
                myPhoneCallListener.setCallListener(new MyPhoneCallListener.CallListener() {
                    @Override
                    public void onCall(String incomingNumber) {
                       closeWindow(MainActivity.this);
                        showActivity(MainActivity.this,incomingNumber);
                        WindowManager wm = (WindowManager) MainActivity.this
                                .getSystemService(Context.WINDOW_SERVICE);
                        int width = wm.getDefaultDisplay().getWidth();
                        int height = wm.getDefaultDisplay().getHeight();
                        showWindow(MainActivity.this,incomingNumber,height);

                    }
                });
                // 注册来电监听
                tm.listen(myPhoneCallListener, PhoneStateListener.LISTEN_CALL_STATE);
            } catch(Exception e) {
                // 异常捕捉
            }
        }
    }

    private void initDate() {
        SharedPreferences share = getSharedPreferences("DG_PHONESHOW", 0);
        String string = share.getString("tableName", "");
        String welcome = share.getString("welcome", "");
        String welcomeen = share.getString("welcomeen", "");
        String phone = share.getString("phone", "");
        this.welcome_edit.setText(welcome);
        this.phone_edit.setText(phone);
        this.welcome_en_edit.setText(welcomeen);
        if ("".equals(this.phone_edit.getText().toString())) {
        }
    }

    /* renamed from: a */
    private int f27a = 0;
    private TelephonyManager telMgr = null;


    private void showActivity(Context ctx, String number) {
        Intent intent = new Intent(ctx, OverLayActivity.class);
        intent.addFlags(268435456);
        intent.putExtra("phoneNum", number);
        ctx.startActivity(intent);
    }

    /* access modifiers changed from: private */
    public void showWindow(Activity ctx, String number, int percentScreen) {
        OverlayView.show(ctx, number, percentScreen);
    }

    /* access modifiers changed from: private */
    public void closeWindow(Context ctx) {
        OverlayView.hide(ctx);
    }


}
